{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import torch\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### _用python实现网络_\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_data=[1.0,2.0,3.0]\n",
    "y_data=[2.0,4.0,6.0]\n",
    "\n",
    "w=torch.Tensor([1.])\n",
    "w.requires_grad=True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def forward(x):\n",
    "    return x*w\n",
    "def loss(x,y):\n",
    "    y_pred=forward(x)\n",
    "    return (y_pred-y)**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "0 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "1 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "2 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "3 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "4 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "5 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "6 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "7 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "8 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "9 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "10 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "11 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "12 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "13 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "14 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "15 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "16 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "17 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "18 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "19 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "20 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "21 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "22 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "23 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "24 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "25 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "26 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "27 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "28 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "29 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "30 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "31 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "32 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "33 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "34 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "35 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "36 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "37 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "38 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "39 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "40 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "41 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "42 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "43 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "44 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "45 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "46 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "47 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "48 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "49 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "50 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "51 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "52 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "53 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "54 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "55 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "56 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "57 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "58 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "59 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "60 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "61 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "62 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "63 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "64 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "65 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "66 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "67 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "68 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "69 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "70 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "71 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "72 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "73 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "74 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "75 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "76 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "77 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "78 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "79 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "80 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "81 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "82 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "83 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "84 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "85 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "86 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "87 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "88 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "89 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "90 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "91 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "92 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "93 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "94 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "95 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "96 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "97 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "98 9.094947017729282e-13\n",
      "\t 1.0 2.0 -7.152557373046875e-07\n",
      "\t 2.0 4.0 -2.86102294921875e-06\n",
      "\t 3.0 6.0 -5.7220458984375e-06\n",
      "99 9.094947017729282e-13\n"
     ]
    }
   ],
   "source": [
    "for epoch in range(100):\n",
    "    for x,y in zip(x_data,y_data):\n",
    "        l=loss(x,y)\n",
    "        l.backward()\n",
    "        print('\\t',x,y,w.grad.item())\n",
    "        w.data=w.data-0.01*w.grad.data\n",
    "        w.grad.data.zero_()\n",
    "    print(epoch,l.item())\n",
    "        \n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
